(function() {
    'use strict';
    angular
        .module('milkbeeApp')
        .factory('CardCategory', CardCategory)
        .factory('CardRecomments', CardRecomments)
        .factory('CardEssences', CardEssences)
        .factory('Card', Card);

    Card.$inject = ['$resource', 'DateUtils'];
    CardCategory.$inject = ['$resource', 'DateUtils'];
    CardRecomments.$inject = ['$resource', 'DateUtils'];
    CardEssences.$inject = ['$resource', 'DateUtils'];

    function Card ($resource, DateUtils) {
        var resourceUrl =  'api/cards/:id';

        return $resource(resourceUrl, {}, {
            'query': { method: 'GET', isArray: true},
            'get': {
                method: 'GET',
                transformResponse: function (data) {
                    if (data) {
                        data = angular.fromJson(data);
                        data.createdAt = DateUtils.convertDateTimeFromServer(data.createdAt);
                        data.modifiedAt = DateUtils.convertDateTimeFromServer(data.modifiedAt);
                    }
                    return data;
                }
            },
            'update': { method:'PUT' }
        });
    }
    function CardCategory ($resource, DateUtils) {
    	var resourceUrl =  'api/card/category/:categoryId';   	
    	return $resource(resourceUrl, {}, {
    		'query': { method: 'GET', isArray: true}	
    	});
    }
    
    
    function CardRecomments($resource, DateUtils){
    	var resourceUrl =  'api/card/recommends/:count';
    	return $resource(resourceUrl, {}, {
    		'query': { method: 'GET', isArray: true}	
    	});
    }
    function CardEssences($resource, DateUtils){
    	var resourceUrl =  'api/card/essences/:count';
    	return $resource(resourceUrl, {}, {
    		'query': { method: 'GET', isArray: true}	
    	});
    }
    
})();
